import {
  RouteConfig,
} from '@/types/router';
import { DELETE, GET, POST, PUT } from '../index';

// 导入
export const excelFileUpload = (data: any = {}) => {
  const tableNameStr = data.table_name ? String(data.table_name) : '';
  const typeStr = data.type ? String(data.type) : '';
  const datasourceIdStr = data.datasource_id ? String(data.datasource_id) : '';
  const dbNameStr = data.db_name ? String(data.db_name) : '';
  const tableFilterStr = data.table_filter ? String(data.table_filter) : '';
  const url = `/api/v2/serve/excel/excel_file/upload?type=${encodeURIComponent(typeStr)}&datasource_id=${encodeURIComponent(datasourceIdStr)}&db_name=${encodeURIComponent(dbNameStr)}&table_name=${encodeURIComponent(tableNameStr)}&table_filter=${encodeURIComponent(tableFilterStr)}`;
  return POST<FormData, any>(url, data.file, {
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  });
};
// 上传进度
export const excelFileUploadProgress = (data: any = {}) => {
  return POST<any, RouteConfig>(`/api/v2/serve/excel/excel_file/upload_progress`)
}
//表格菜单列表
export const getTableMenuList = (data: any = {}) => {
  return POST<any, RouteConfig>(`/api/v2/serve/excel/excel_file/list`, data)
}
//获取RDBMS数据源列表
export const getRDBMSDataSourceList = (data: any = {}) => {

  return GET<any, RouteConfig>(`/api/v2/serve/datasource-rdbms`, data)
}
//获取数据表列表
export const getTableList = (datasource_id: string) => {
  return GET<any, RouteConfig>(`/api/v2/serve/datasource-rdbms-tables?datasource_id=` + datasource_id)
}
//表格复制
export const copyTable = (data: any = {}) => {
  return POST<any, RouteConfig>(`/api/v2/serve/excel/excel_file/copy`, data)
}
//表格回收站
export const getTableTrash = (data: any = {}) => {
  return POST<any, RouteConfig>(`/api/v2/serve/excel/excel_file/recycle_bin`, data)
}
//回收站还原
export const restoreTable = (data: any = {}) => {
  return POST<any, RouteConfig>(`/api/v2/serve/excel/excel_file/recycle_bin_cancel`, data)
}
//彻底删除
export const deleteTable = (data: any = {}) => {
  return POST<any, RouteConfig>('/api/v2/serve/excel/excel_file/delete', data)
}
//清除导入和上传的记录
export const deleteUploadprogress = (data: any = {}) => {
   return POST<any,RouteConfig>('/api/v2/serve/excel/excel_file/delete_upload_progress',data)
}